package com.ecplatform.item.controller;

import com.ecplatform.common.pojo.po.PageResult;
import com.ecplatform.common.pojo.po.Result;
import com.ecplatform.item.pojo.vo.ItemVO;
import com.ecplatform.item.service.IItemService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/items")
public class ItemController {

    private final IItemService itemService;

    /**
     * 商品分页查询
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult<ItemVO>> itemsPageQuery (@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                      @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return Result.success(itemService.itemPageQuery(pageNum, pageSize));
    }

    @GetMapping
    public ItemVO selectItemById(@RequestParam("id") Long id) {
        return itemService.selectItemById(id);
    }
}
